﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TiTi.tea.Comm;
using TiTi.tea.DAL;
using TiTi.tea.Dto;
using TiTi.tea.Model;

namespace TiTi.tea.BLL
{
    public class TemplateBLL
    {
        private TemplateDAL dal = new TemplateDAL();


        public IEnumerable<Template> Query(string TplName, out int Total, int PageIndex, int PageSize)
        {
            var page = new PagePara(PageIndex, PageSize);
            if (string.IsNullOrEmpty(TplName))
            {
                TplName = "";
            }
            var data = dal.GetAll(o => o.TplName.Contains(TplName));
            Total = page.Total;
            return data;
        }


        /// <summary>
        /// 获取全部模板
        /// </summary>
        /// <param name="tplName"></param>
        /// <returns></returns>
        public IEnumerable<TemplateDto> GetAll(string tplName)
        {
            return dal.GetAll(o=>o.IsDelete==0&&o.TplName.Contains(tplName)).Select(o=>new TemplateDto()
            {
                Id=o.Id,
                TplName = o.TplName,
            });
        }
        public Template GetOne(int id)
        {
            return dal.GetOne(o => o.Id == id);
        }
        public bool Add(Template entity)
        {
           
            return dal.Add(entity);
        }
        public bool Update(Template entity)
        {
            return dal.Update(entity);
        }
        public bool Delete(int Id)
        {
            var data = dal.GetOne(o => o.Id == Id);
            data.IsDelete = 1;
            return dal.Update(data);

        }
    }
}
